package cn.hwadee.muying.service;

import cn.hwadee.muying.entity.PromotionLog;
import cn.hwadee.muying.entity.WorkerLevel;
import cn.hwadee.muying.mapper.PromotionLogMapper;
import cn.hwadee.muying.commons.base.BaseService;
import org.springframework.stereotype.Service;
import cn.hwadee.muying.entity.User;
import cn.hwadee.muying.commons.page.MyPage;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.List;

/**
 * <p>
 * 晋升记录 服务实现类
 * </p>
 *
 * @author Mankind
 * @since 2018-08-06
 */
@Service
public class PromotionLogService extends BaseService<PromotionLogMapper, PromotionLog> {

    @Autowired
    private PromotionLogMapper promotionLogMapper;

    @Autowired
    private UserService userService;

    @Autowired
    private WorkerLevelService workerLevelService;

    public MyPage<PromotionLog> list(MyPage<PromotionLog> page, User cUser,Long userId,Long preWorkerLevelId,Long curWorkerLevelId,String keyword) throws Exception{
        List<PromotionLog> promotionLogs = promotionLogMapper.list(page,cUser,userId,preWorkerLevelId,curWorkerLevelId,keyword);
        for(PromotionLog promotionLog:promotionLogs){
            User user=userService.selectById(promotionLog.getUserId());
            promotionLog.setUserName(user.getUsername());
            WorkerLevel workerLevel=workerLevelService.selectById(promotionLog.getPreLevelId());
             //System.out.println(promotionLog.getPreLevelId());
            promotionLog.setPreWorkerLevelName(workerLevel.getName());
            workerLevel=workerLevelService.selectById(promotionLog.getCurLevelId());
            promotionLog.setCurWorkerLevelName(workerLevel.getName());
        }
        page.setRecords(promotionLogs);
        return page;
    }

}
